package com.nsl.my_youlai.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nsl.my_youlai.common.model.ElSelectOption;
import com.nsl.my_youlai.mapper.SysDictMapper;
import com.nsl.my_youlai.model.entity.SysDict;
import com.nsl.my_youlai.service.SysDictService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class SysDictServiceImpl extends ServiceImpl<SysDictMapper, SysDict> implements SysDictService {
    @Override
    public List<ElSelectOption> listDictOptions(String typeCode) {
        // 数据字典项
        List<SysDict> dictList = this.list(new LambdaQueryWrapper<SysDict>()
                .eq(SysDict::getTypeCode, typeCode)
                .select(SysDict::getValue, SysDict::getName)
        );

        // 转换下拉数据
        List<ElSelectOption> elSelectOptions = CollectionUtil.emptyIfNull(dictList)
                .stream()
                .map(dictItem -> new ElSelectOption(dictItem.getValue(), dictItem.getName()))
                .collect(Collectors.toList());
        return elSelectOptions;
    }
}
